//
//  String+extension.swift
//  正则表达式
//
//  Created by hqhxu on 16/3/7.
//  Copyright © 2016年 hqhxu. All rights reserved.
// 匹配相应的字符串

import Foundation

extension String {
    
     func regularType() ->String{
        
        let pattern = ">(.*?)<"
        
        let regular = try! NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
        
        let nsStr = self as NSString
        
        let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, nsStr.length))
        
        let range = result?.range
        
        var type = "未知来源"
        
        if range != nil {
            
            type = nsStr.substringWithRange(NSMakeRange(range!.location + 1, range!.length - 2))
        }
        return type
    }
    
}
